function addSeriesToPayload(payload, name, serieName, xname, yname) {
    var rows = payload["rows"]
    var logMap = {}
    var series = []
    // 如果含有无效值会导致图表无法显示
    rows = rows.filter((x) => x[yname] ? true : false)
    var lineNames = []
    for (i = 0; i < rows.length; i++) {
        r = rows[i]
        if (!logMap[r[serieName]]) {
            var tmp = {}
            tmp["name"] = r[serieName]
            tmp["type"] = 'line'
            tmp["smooth"] = true
            tmp["__rel"] = r
            tmp["data"] = rows.filter((x) => x[serieName] == tmp["name"]).map((x) => [x[xname], x[yname]])
            // tmp["markPoint"] = {
            //     data: [
            //         {type: 'max', name: '最大值'},
            //         {type: 'min', name: '最小值'}
            //     ]
            // }
            logMap[r[serieName]] = tmp
            series.push(logMap[r[serieName]])
            if (!lineNames.includes(r[serieName])) {
                lineNames.push(r[serieName]);
            }
        }
    }
    if (payload["__keys"] && !payload["__keys"].includes(name)) {
        payload["__keys"].push(name)
    }
    payload[name] = series
    payload["lastUpdateTime"] = Date.now()
    payload[name + "_" + "lastUpdateTime"] = Date.now()
    payload[name + "_" + "lineNames"] = lineNames
    return {
        ...payload
    }
}

function mergeSeries(payload, name, after = false, serieNameTmp = "${key}-${serieName}") {
    if (after) {
        var series = []
        var keys = payload["__keys"]
        var lineNames = []
        for (i = 0; i < keys.length; i++) {
            let key = keys[i];
            var list = payload[key]
            for (j = 0; j < list.length; j++) {
                list[j]["name"] = formatLineName(key, list[j]["name"], serieNameTmp, list[j]["__rel"])
                if (!lineNames.includes(list[j]["name"])) {
                    lineNames.push(list[j]["name"]);
                }
                delete list[j]["__rel"]
                series.push(list[j])
            }
            delete payload[key]
            delete payload[key + "_" + "lastUpdateTime"]
        }
        payload[name] = series
        payload[name + "_" + "lastUpdateTime"] = Date.now()
        payload[name + "_" + "lineNames"] = lineNames
    }
    payload["__keys"] = []
}

function formatLineName(key, serieName, serieNameTmp, row) {
    let name = key.split("__")[0]
    let line = serieName
    let mergeKey = key.split("__")[1]
    return eval("`" + serieNameTmp + "`")
}